package com.ruoyi.web.controller.tea;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.Teas;
import com.ruoyi.web.domain.VO.TeasVo;
import com.ruoyi.web.service.ITeasService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 茶叶管理Controller
 *
 * @author xuzhisen
 * @date 2022-08-18
 */
@RestController
@RequestMapping("/tea/teas")
public class TeasController extends BaseController
{
    @Autowired
    private ITeasService teasService;

    @PreAuthorize("@ss.hasPermi('tea:teas:list1')")
    @GetMapping("/list1")
    public TableDataInfo list1(TeasVo teasVo)
    {
        startPage();
        List<TeasVo> list = teasService.selectTeasList1(teasVo);
        return getDataTable(list);
    }



    /**
     * 查询茶叶管理列表
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:list')")
    @GetMapping("/list")
    public TableDataInfo list(Teas teas)
    {
        startPage();
        List<Teas> list = teasService.selectTeasList(teas);
        return getDataTable(list);
    }

    /**
     * 导出茶叶管理列表
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:export')")
    @Log(title = "茶叶管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Teas teas)
    {
        List<Teas> list = teasService.selectTeasList(teas);
        ExcelUtil<Teas> util = new ExcelUtil<Teas>(Teas.class);
        util.exportExcel(response, list, "茶叶管理数据");
    }

    /**
     * 获取茶叶管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:query')")
    @GetMapping(value = "/{teaId}")
    public AjaxResult getInfo(@PathVariable("teaId") Long teaId)
    {
        return AjaxResult.success(teasService.selectTeasByTeaId(teaId));
    }

    /**
     * 新增茶叶管理
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:add')")
    @Log(title = "茶叶管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Teas teas)
    {
        return toAjax(teasService.insertTeas(teas));
    }

    /**
     * 修改茶叶管理
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:edit')")
    @Log(title = "茶叶管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Teas teas)
    {
        return toAjax(teasService.updateTeas(teas));
    }

    /**
     * 删除茶叶管理
     */
    @PreAuthorize("@ss.hasPermi('tea:teas:remove')")
    @Log(title = "茶叶管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teaIds}")
    public AjaxResult remove(@PathVariable Long[] teaIds)
    {
        return toAjax(teasService.deleteTeasByTeaIds(teaIds));
    }
}
